package com.seredius.ui;

import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;


public class SystemTrayTest
{
   
    public SystemTrayTest() throws Exception
    {
       
        final TrayIcon trayIcon;
        final Runtime rt= Runtime.getRuntime();
        if (SystemTray.isSupported()) {

            SystemTray tray = SystemTray.getSystemTray();
            Image image = Toolkit.getDefaultToolkit().getImage("star.jpg");
           
   
            ActionListener exitListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Exiting...");
                    System.exit(0);
                }
            };
           
            PopupMenu popup = new PopupMenu();
            MenuItem defaultItem = new MenuItem("Exit");
            defaultItem.addActionListener(exitListener);
            popup.add(defaultItem);

            trayIcon = new TrayIcon(image, "StartCraft", popup);

            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
      rt.exec("C:/Program Files/Starcraft/StarCraft.exe");
     } catch (IOException e1) {
       trayIcon.displayMessage("Action Event",
                           "StarCraft is not found !",
                           TrayIcon.MessageType.INFO);
     }
                }
            };
           
            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(actionListener);
           
            tray.add(trayIcon);
        } else {
            System.err.println("System tray is currently not supported.");
        }
    }
   
 public static void main(String[] args) throws Exception
    {
        SystemTrayTest main = new SystemTrayTest();
    }
   
}